//
//  WebViewController.swift
//  funcode
//
//  Created by Wan Jiading on 2016/11/10.
//  Copyright © 2016年 WanJiading. All rights reserved.
//

import UIKit
import WebKit
import SnapKit

class WebViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

	var urlStrig: String!
	var webView: WKWebView!
	
    override func viewDidLoad() {
        super.viewDidLoad()

		setupSubview()
    }
	
	func setupSubview() {
		webView = WKWebView()
		
		let url = URL(string: urlStrig)!
		let req = URLRequest(url: url)
		webView.load(req)
		webView.navigationDelegate = self
//		webView.uiDelegate = self
		self.view.addSubview(webView)
		
		webView.snp.makeConstraints { (make) in
//			make.edges.equalTo(self.view).
			make.edges.equalTo(self.view).inset(UIEdgeInsets.zero)
		}
		
//		self.webView.frame = self.view.bounds
		
	}

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

extension WebViewController {
	func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
		debugPrint(error)
	}
	
	func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
		debugPrint("加载完成")
	}
	
	func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
		debugPrint("didStartProvisionalNavigation")
	}
	
	func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
		debugPrint("didCommit")
	}
	
	
	
//	func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
//		debugPrint("didReceiveServerRedirectForProvisionalNavigation")
//	}
//	func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
//		debugPrint("decidePolicyFor navigationResponse")
//	}
//	func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
//		debugPrint("decidePolicyFor navigationAction")
//	}
}
